import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'

// https://vite.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': resolve(__dirname, 'src')
    }
  },
  define: {
    __API_BASE_URL__: JSON.stringify('')  // 使用相对路径，让Nginx代理生效
  },
  server: {
    port: 8082,
    proxy: {
      '/api': {
        target: 'http://localhost:8090',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '') // 移除/api前缀，因为后端可能不需要
      },
      '/lunbo': {
        target: 'http://localhost:8090',
        changeOrigin: true,
        rewrite: (path) => path // 保持 /lunbo 路径不变
      },
      '/banner': {
        target: 'http://localhost:8090',
        changeOrigin: true,
        rewrite: (path) => path // 保持 /banner 路径不变
      }
    }
  }
})
